package vcp.models;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;



import java.util.Observable;

import javax.swing.JOptionPane;

import client.Message;
import vcp.common.AbstractModel;
import control.SimpleClient;
import db.parking.beans.Complaints;

/**
 * Resolve Complaints Model 
 *
 */
public class ResolveComplaintsModel extends Observable implements PropertyChangeListener {
	
	protected SimpleClient client = null;
	protected Message msg = null;

	

	/**
	 * load Complaints Table Model request
	 */
	public void loadComplaintsTableModel() {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);
		Message msg = new Message(null,"GetComplaints");
		 try {
				client.sendToServer(msg);				
		 }
		 catch (Exception ex)
		 {
			 System.out.println(ex.toString()+"get->GetComplaints");
		 }	
		
		
	}

	

	/**
	 * update Resolved Status request
	 * @param comp
	 */
	public void updateResolvedStatus(Complaints comp) {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);
		Message msg = new Message(comp,"UpdateResolvedStatus");
		 try {
				client.sendToServer(msg);				
		 }
		 catch (Exception ex)
		 {
			 System.out.println(ex.toString()+"get->UpdateResolvedStatus");
		 }	
		
	}
	
	
	/* (non-Javadoc)
	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
	 */
	@Override
	public void propertyChange(PropertyChangeEvent event) {
		if (event.getPropertyName().equals("MessageUpdate")) {			    
		    msg = client.getReturnMsg();
		    if(msg.isStatus() && msg.getMsg().equals("UpdateResolvedStatus")){
		    	System.out.println("modified");
		    }else if(msg.isStatus() && msg.getMsg().equals("UpdateResolveAmount")){
		    	JOptionPane.showMessageDialog(null,
		    		    "Customer refunded.");
		    }else{
		    	setChanged();
		    	notifyObservers(msg);	
		    }
		   		
        }
		
		client.clearPropertyChangeListener();

	}



	/**
	 * update Resolve Amount request
	 * @param comp
	 */
	public void updateResolveAmount(Complaints comp) {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);
		Message msg = new Message(comp,"UpdateResolveAmount");
		 try {
				client.sendToServer(msg);				
		 }
		 catch (Exception ex)
		 {
			 System.out.println(ex.toString()+"get->UpdateResolveAmount");
		 }	
	}
    
}
